<?php

class Transactions extends Controller {

	function __construct() {
		parent::Controller();	
	}
	
	function index() {
		//Use this for your home page
		$data['title'] = "imerchant : City's Home";
		$data['main'] = 'transactions/home';
		$this->load->vars($data);
		$this->load->view('template');
	}
	
	function add_transactions() {
		//Add transactions
		$data['title'] = "imerchant: Add transactions";
		$data['main'] = 'transactions/add_transactions';
		$this->load->vars($data);
		$this->load->view('template');
	}
	
	function send() {
		if($this->input->post('submit')) {
			$this->Mtransactions->addTransaction();
			$data['title'] = "imerchant";
			$data['main'] = 'transactions/sent';
			$this->load->vars($data);
			$this->load->view('template');
		} else {
		 show_error("This is not working");
		} 
	}
	
	function view_transactions() {
		//View transactions
		$data['title'] = "imerchant";
		$data['main'] = 'transactions/view_transactions';
		$data['result'] = $this->Mtransactions->getAllTransactions();
		$this->load->vars($data);
		$this->load->view('template');
	}
	
	function delete() {
		//Delete transactions
		$del_rows=0;
		if($this->input->post('delete')) {
			@$item=$_POST['item'];
			while (list ($key, $sel_id) = @each ($item)) { 
				$this->Mtransactions->deleteTransaction($sel_id);
				$del_rows++; 
			} 
			
			$data['main'] = 'transactions/delete';
			$data['del_rows'] = $del_rows;
			$this->load->vars($data);
			$this->load->view('template');
			
		} else {
		 show_error("This is not working");
		} 
	}
	
	function edit($id) {
		//Edit transactions
		$data['result'] = $this->Mtransactions->getTransaction($id);
		$data['main'] = 'transactions/edit';
		$this->load->vars($data);
		$this->load->view('template');	
	}
	
	function update() {
		//update transactions
		$id = $_POST['id'];
		if($this->input->post('update')) {
			$this->Mtransactions->updateTransaction($id);
			$data['title'] = "imerchant";
			$data['main'] = 'transactions/update';
			$this->load->vars($data);
			$this->load->view('template');
		} else {
		 show_error("This is not working");
		} 
	}
}

/* End of file transactions.php */